package com.bsoft.project.base;


import java.util.HashMap;
import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.beans.factory.annotation.Autowired;

import com.bsoft.project.model.MlcxVo;
import com.bsoft.project.model.MlcxVoExcel;
import com.bsoft.project.model.ZfblVo;
import com.bsoft.project.model.ZfblVoExcela;

/**
 * Created by Administrator on 2019/12/11.
 */
public class BaseDao extends SqlSessionDaoSupport {
    private static final Logger logger = LogManager.getLogger(BaseDao.class);
    @Autowired
    public void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate){
        super.setSqlSessionTemplate(sqlSessionTemplate);
    }

    /*public <T> List<T> selectList(Class<T> T, String mappId, Object arg){
        return (List<T>)this.getSqlSessionTemplate().selectList(mappId,arg);
    }
    public <T> List<T> selectList(Class<T> T, String mappId){
        return (List<T>)this.getSqlSessionTemplate().selectList(mappId,null);
    }
    
    public <T> T selectOne(Class<T> T,String mappId,Object arg){
        return (T)this.getSqlSessionTemplate().selectOne(mappId,arg);
    }

    protected int insert(String mappId,Object arg){
        return this.getSqlSessionTemplate().insert(mappId,arg) ;
    }

    protected int update(String mappId,Object arg){
        return this.getSqlSessionTemplate().update(mappId,arg) ;
    }
    protected int delete(String mappId,Object arg){
        return this.getSqlSessionTemplate().delete(mappId,arg) ;
    }
    
    public int countByNamedSql(String nameSqlId,Object arg){
        Integer num = this.selectOne(Integer.class,nameSqlId,arg) ;
        if(num==null){
            return 0;
        }
        return num;
    }

    public int deleteBatch(String nameSqlId,List list){
        int retVal = 0;
        for(Object obj:list){
            retVal+=this.delete(nameSqlId,obj) ;
        }
        return retVal;
    }*/
    

    public List<HashMap<String, Object>> selectListWithOutParams(String mappId){
        return this.getSqlSessionTemplate().selectList(mappId);
    }
    
    public List<HashMap<String, Object>> selectListWithParams(String mappId,HashMap<String,Object> params){
        return this.getSqlSessionTemplate().selectList(mappId,params);
    }
    
    public int getRbxxCount(String mappId,HashMap<String,Object> params){
        return this.getSqlSessionTemplate().selectOne(mappId,params);
    }
    
    public int updateGhjsToOne(String mappId){
        return this.getSqlSessionTemplate().delete(mappId);
    }
    
    public int deleteWithOutParams(String mappId){
        return this.getSqlSessionTemplate().delete(mappId) ;
    }
    
    public int updateWithOutParams(String mappId){
        return this.getSqlSessionTemplate().update(mappId) ;
    }
    
    public HashMap<String, Object> getTxcsInfo(String mappId,@Param("csmc")String param){
        return this.getSqlSessionTemplate().selectOne(mappId, param);
    }
    
    protected int insert(String mappId, HashMap<String,Object> params){
        return this.getSqlSessionTemplate().insert(mappId,params) ;
    }
    
    protected int insert(String mappId, List<String[]> list){
        return this.getSqlSessionTemplate().insert(mappId,list) ;
    }
    
    protected int insert(String mappId, @Param("str")String str){
        return this.getSqlSessionTemplate().insert(mappId,str) ;
    }
    
    protected int insert(String mappId, String[] param){
        return this.getSqlSessionTemplate().insert(mappId,param) ;
    }
    
    
    public int isExists(String mappId,HashMap<String,Object> params){
        return this.getSqlSessionTemplate().selectOne(mappId,params);
    }
    
    public int updateDownloadVersion(String mappId,HashMap<String,Object> params){
//        return this.getSqlSessionTemplate().update(mappId,params);
    	return this.getSqlSessionTemplate().insert(mappId,params);
    }
    
    
    public String getXtCsz(String nameSqlId,HashMap<String,Object> params){
        String csz = this.getSqlSessionTemplate().selectOne(nameSqlId,params);
        return csz;
    }
    
    public int insertXTCS(String mappId,HashMap<String,Object> params){
        return this.getSqlSessionTemplate().insert(mappId,params);
    }
    
    
    public int getJlId(String mappId,HashMap<String,Object> params){
        return this.getSqlSessionTemplate().selectOne(mappId,params);
    }
    
    public void insertGyIdentity(String mappId){
        this.getSqlSessionTemplate().insert(mappId);
    }
    
    public void updateGyIdentity(String mappId){
        this.getSqlSessionTemplate().update(mappId);
    }
    
    public int insertDownloadVersion(String mappId,HashMap<String,Object> params){
        return this.getSqlSessionTemplate().insert(mappId,params);
    }
    
    public int insertUpdateZFBL(String mappId,ZfblVo vo){
        return this.getSqlSessionTemplate().insert(mappId,vo);
    }
    
    public String getMaxZfblUpdate(String mappId){
        return this.getSqlSessionTemplate().selectOne(mappId);
    }
    
    public String getMaxMlcxUpdate(String mappId){
        return this.getSqlSessionTemplate().selectOne(mappId);
    }
    
    public int insertUpdateMLCX(String mappId,MlcxVo vo){
        return this.getSqlSessionTemplate().insert(mappId,vo);
    }
    
    public int insertUpdateMLCXExcel(String mappId,MlcxVoExcel vo){
        return this.getSqlSessionTemplate().insert(mappId,vo);
    }
    
    public int insertUpdateZfblExcel(String mappId,ZfblVoExcela vo){
        return this.getSqlSessionTemplate().insert(mappId,vo);
    }
    
}
